Interpret patterns where the first byte of the mask is '*' as unanchored.
authorMatthias Clasen <mclasen@redhat.com>
Fri, 22 Jul 2005 04:37:27 +0000 (04:37 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Fri, 22 Jul 2005 04:37:27 +0000 (04:37 +0000)
2005-07-22  Matthias Clasen  <mclasen@redhat.com>

* gdk-pixbuf-io.c (format_check): Interpret patterns where
the first byte of the mask is '*' as unanchored.  (#311011)
(gdk_pixbuf_new_from_file): Use the first 256 bytes for
sniffing the file format.

docs/reference/ChangeLog
docs/reference/gdk-pixbuf/tmpl/module_interface.sgml
gdk-pixbuf/ChangeLog
gdk-pixbuf/gdk-pixbuf-io.c

index a423a0e2af22d776d87d7a867df0898a573be13b..0fc148de120c1c530f7359a1faf38b4edbfd0952 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-22  Matthias Clasen  <mclasen@redhat.com>
+
+       * gdk-pixbuf/tmpl/module_interface.sgml: Document unanchored 
+       patterns.
+
 2005-07-21  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/tmpl/gtkfilechooserdialog.sgml (dialog): Expand the Save
index ac12c39e38d4b93cb5c6c8728a2dc172e9f2d9cb..e06b0d325081b16d05f97a89c8aa225ee8cc4e15 100644 (file)
@@ -204,14 +204,19 @@ operations.
 <!-- ##### STRUCT GdkPixbufModulePattern ##### -->
 <para>
 The signature of a module is a set of prefixes. Prefixes are encoded as
-pairs of ordinary strings, where the second string, if not %NULL, must be
-of the same length as the first one and may contain ' ', '!', 'x', 'z', 
-and 'n' to indicate bytes that must be matched, not matched, 
-"don't-care"-bytes, zeros and non-zeros.
+pairs of ordinary strings, where the second string, called the mask, if 
+not %NULL, must be of the same length as the first one and may contain 
+' ', '!', 'x', 'z', and 'n' to indicate bytes that must be matched, 
+not matched, "don't-care"-bytes, zeros and non-zeros. 
 Each prefix has an associated integer that describes the relevance of 
 the prefix, with 0 meaning a mismatch and 100 a "perfect match".
 </para>
-
+<para>
+Starting with &gdk-pixbuf; 2.8, the first byte of the mask may be '*', 
+indicating an unanchored pattern that matches not only at the beginning, 
+but also in the middle. Versions prior to 2.8 will interpret the '*'
+like an 'x'. 
+</para>
 <para>
 The signature of a module is stored as an array of 
 #GdkPixbufModulePattern<!-- -->s. The array is terminated by a pattern
index a58d80bf916fec376da66201ae44daf0fd31591c..c79228407682f088676cb93c2da1d7e71c9bb1d9 100644 (file)
@@ -1,3 +1,10 @@
+2005-07-22  Matthias Clasen  <mclasen@redhat.com>
+
+       * gdk-pixbuf-io.c (format_check): Interpret patterns where
+       the first byte of the mask is '*' as unanchored.  (#311011)
+       (gdk_pixbuf_new_from_file): Use the first 256 bytes for
+       sniffing the file format.
+
 2005-07-15  Matthias Clasen  <mclasen@redhat.com>
 
        * === Released 2.7.3 ===
index dc0408d2f7214aa573c5dc655bd29c8787006e07..a8faa782f9bface00e013ff96a22fefe77cd6f32 100644 (file)
 static gint 
 format_check (GdkPixbufModule *module, guchar *buffer, int size)
 {
-       int j;
+       int i, j;
        gchar m;
        GdkPixbufModulePattern *pattern;
+       gboolean unanchored;
+       guchar *prefix, *mask;
 
        for (pattern = module->info->signature; pattern->prefix; pattern++) {
-               for (j = 0; j < size && pattern->prefix[j] != 0; j++) {
-                       m = pattern->mask ? pattern->mask[j] : ' ';
-                       if (m == ' ') {
-                               if (buffer[j] != pattern->prefix[j])
-                                       break;
-                       }
-                       else if (m == '!') {
-                               if (buffer[j] == pattern->prefix[j])
-                                       break;
-                       }
-                       else if (m == 'z') {
-                               if (buffer[j] != 0)
-                                       break;
-                       }
-                       else if (m == 'n') {
-                               if (buffer[j] == 0)
-                                       break;
-                       }
-               } 
-               if (pattern->prefix[j] == 0) 
-                       return pattern->relevance;
+               if (pattern->mask && pattern->mask[0] == '*') {
+                       prefix = pattern->prefix + 1;
+                       mask = pattern->mask + 1;
+                       unanchored = TRUE;
+               }
+               else {
+                       prefix = pattern->prefix;
+                       mask = pattern->mask;
+                       unanchored = FALSE;
+               }
+               for (i = 0; unanchored && i < size; i++) {
+                       for (j = 0; i + j < size && prefix[j] != 0; j++) {
+                               m = mask ? mask[j] : ' ';
+                               if (m == ' ') {
+                                       if (buffer[i + j] != prefix[j])
+                                               break;
+                               }
+                               else if (m == '!') {
+                                       if (buffer[i + j] == prefix[j])
+                                               break;
+                               }
+                               else if (m == 'z') {
+                                       if (buffer[i + j] != 0)
+                                               break;
+                               }
+                               else if (m == 'n') {
+                                       if (buffer[i + j] == 0)
+                                               break;
+                               }
+                       } 
+                       if (prefix[j] == 0) 
+                               return pattern->relevance;
+               }
        }
        return 0;
 }
@@ -821,7 +835,7 @@ gdk_pixbuf_new_from_file (const char *filename,
        GdkPixbuf *pixbuf;
        int size;
        FILE *f;
-       guchar buffer [128];
+       guchar buffer[256];
        GdkPixbufModule *image_module;
        gchar *display_name;